package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author huan
 * @serial 每天一百行, 致敬未来的自己
 * @Description
 */

@RestController
@RequestMapping("/api/v1/author")
@Api(value = "APP文章作者管理", tags = "APP文章作者管理")
public class AuthorController {

    @Autowired
    private AuthorService authorService;

    @GetMapping("/findByUserId/{id}")
    @ApiOperation("根据用户id查询作者信息")
    public ResponseResult findByUserId(@PathVariable("id") Integer id) {
       ApAuthor author = authorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId, id));
        return ResponseResult.okResult(author);
    }
    @PostMapping("/save")
    @ApiOperation("保存作者")
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        apAuthor.setCreatedTime(new Date());
        authorService.save(apAuthor);
        return ResponseResult.okResult();
    }
}
